A linear data structure operating on the FILO (First In, Last Out) principle.

  • A stack is a linear data structure modeled on a physical sequence, such as a pile of plates or books.
  • Elements can only be inserted or deleted at one designated end, commonly referred to as the top, which is managed by an index variable `$top$`.
  • This strict access control ensures that the stack operates according to the FILO (First In, Last Out) principle.
  • The primary operations, which form the stack's interface, are:
    • Push: Adding a new item to the `top` of the stack.
    • Pop: Removing and returning the item currently at the `top`.
    • Peek: Viewing the item at the `top` without removing it.

Stack Operations & Complexity

Operation Description Complexity
Push Add an element to the top. $O(1)$
Pop Remove element from the top. $O(1)$
Peek / Top View the top element. $O(1)$